using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MinimizeEngine.Managers
{
    public sealed class METextureManager : GameComponent
    {
        #region Fields

        /// <summary>
        /// List of all Texture2D's in the Engine
        /// </summary>
        private static Dictionary<string, Texture2D> mLoadedTexture2D = new Dictionary<string, Texture2D>();

        /// <summary>
        /// List of all Texture3D's in the Engine
        /// </summary>
        private static Dictionary<string, Texture3D> mLoadedTexture3D = new Dictionary<string, Texture3D>();

        #endregion

        #region Properties

        /// <summary>
        /// Add a Texture2D into the Engine
        /// </summary>
        public static void AddTexture2D(string name, string pathName)
        {
            if(!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(pathName))
            {
                mLoadedTexture2D.Add(name, MEEngineManager.ContentManager.Load<Texture2D>(pathName));
            }
        }

        /// <summary>
        /// Add a Texture3D into the Engine
        /// </summary>
        public static void AddTexture3D(string name, string pathName)
        {
            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(pathName))
            {
                mLoadedTexture3D.Add(name, MEEngineManager.ContentManager.Load<Texture3D>(pathName));
            }
        }

        /// <summary>
        /// Get a Texture 2D
        /// </summary>
        /// <param name="textureName"></param>
        /// <returns>The requested Texture2D, or Null if it does not exist</returns>
        public static Texture2D GetTexture2D(string textureName)
        {
            if(!string.IsNullOrEmpty(textureName) && mLoadedTexture2D.ContainsKey(textureName))
            {
                return mLoadedTexture2D[textureName];
            }
            return null;
        }

        /// <summary>
        /// Get a Texture3D
        /// </summary>
        /// <param name="textureName">Name of the Texture2D</param>
        /// <returns>The requested Texture3D, or Null if it does not exist</returns>
        public static Texture3D GetTexture3D(string textureName)
        {
            if (!string.IsNullOrEmpty(textureName) && mLoadedTexture3D.ContainsKey(textureName))
            {
                return mLoadedTexture3D[textureName];
            }
            return null;
        }

        #endregion

        #region Initialization

        /// <summary>
        /// Construct a new Texture Manager
        /// </summary>
        /// <param name="game"></param>
        public METextureManager(Game game) : base(game)
        {

        }

        /// <summary>
        /// Initialize the Texture Manager.
        /// Load all Texture in the List.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
        }

        #endregion
    }
}